package com.zy.servlet.order;

import com.zy.entity.Order;
import com.zy.service.GetOrderService;
import com.zy.service.impl.GetOrderServiceImpl;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/getOrders")
public class GetOrderServlet extends HttpServlet {
    private GetOrderService getOrderService = new GetOrderServiceImpl();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        if (req.getSession().getAttribute("loggedIn") == null) {
            resp.sendRedirect("login.jsp");
            return;
        }
        int userId = (int) req.getSession().getAttribute("userId");
        List<Order> orders = getOrderService.getOrders(userId);
        req.setAttribute("orders", orders);
        req.getRequestDispatcher("order.jsp").forward(req, resp);
    }
} 